<?php

	function getConvertedCurrency($url = null, $strBegin = null, $strEnd = null)
	{
    	/*
    	 * Default values
    	 */
    	
    	$default_url = 'http://www.vietcombank.com.vn/';
    	$default_strBegin = '<!--exchange rates-->';
    	$default_strEnd = '<!--end exchange-->';
    	
    	/*
    	 * If Parameter is NULL
    	 * Set Parameter is DEFAULT VALUES
    	 */
    	
    	if($url == null)
    	{
    		$url = $default_url;
    	}
    	if($strBegin == null)
    	{
    		$strBegin = $default_strBegin;
    	}
    	if($strEnd == null)
    	{
    		$strEnd = $default_strEnd;
    	}
    	
    	/*
    	 * Get content of webpage
    	 */
		$content = @file_get_contents($url);
		
		/*
		 * Define return array
		 */
		$returnArray = array();
		
		/*
		 * Check position begin and end is exist
		 */
	    $posBegin = strpos($content, $strBegin);
	    $posEnd = strpos($content, $strEnd);
	    
	    if($posBegin == false || $posEnd == false)
	    {
	    	// Valid
	    	// Rerturn Error is true
	    	
	    	$returnArray['Error'] = 'true';
	    }
	    else
	    {
	    	// Invalid
	    	// Proccess
	        
	        $content = substr($content, $posBegin, ($posEnd - $posBegin));
			$set = array('<td class="code">','<th scope="col">','</th>','</td>','<td>');

			$arr = str_replace($set, '/', strip_tags($content, '<td><th>'));
	        $arr = str_replace('//', '/', $arr);
	        $arr = explode('/', $arr);

	        $string = array();
	        foreach($arr as $k => $v)
	        {
	        	if(ereg('[a-z A-Z 0-9]', $v))
	        	{
	        		$string[] = $v;
	        	}
	        }

	        foreach($string as $k => $v)
	        {
	        	if(($k-0)%4 == 0)
	        	{
	        		$returnArray['Code'][] = $v;
	        	} 
	        	else 
	        	{
	        		if(($k-1)%4 == 0)
	        		{
	        			$returnArray['BuyCash'][] = $v;
	        		} 
	        		else 
	        		{
	        			if(($k-2)%4 == 0)
	        			{
	        				$returnArray['BuyYourMove'][] = $v;
	        			} 
	        			else 
	        			{
	        				if(($k-3)%4 == 0)
	        				{	
	        					$returnArray['Sell'][] = $v;
	        				}
	        			}
	        		}
	        	}
	        }
	    }
	
	    return $returnArray;
    	
    }	
   
    $convertedCurrency = getConvertedCurrency()
    
?>
<style>
	.currentcy{
		text-align: center; 
		width: 120px;
	}
	.currentcy td{
		padding: 5px;
	}
	.currentcyDiv{
		margin: auto;
	}
	.viewsource{
		width: 225px;
		height: auto;;
		padding: 10px;	
		overflow-x: scroll;
	}
	#viewsource p{
		white-space: pre;
	}
</style>
<div class='currentcyDiv' style="text-align: center;">
	<table cellpadding="0" cellspacing="0" align="center" class='currentcy' id='tableCurrentcy' style="margin: auto; border: solid 1px #CCC; border-bottom: none;">
		<tr>
			<td colspan="2" style="border-bottom: 1px solid #CCC;font-weight: bold;">
				Bảng tỷ giá tiền tệ				
			</td>
		</tr>
	<?php 
		foreach($convertedCurrency['Code'] as $k => $v)
		{ if ($k != 0){
	?>
		<tr>
			<td style="border-bottom: solid 1px #CCC; border-right: solid 1px #CCC"><?= $v ?></td>
			<td style="border-bottom: solid 1px #CCC"><?= $convertedCurrency['Sell'][$k] ?></td>
		</tr>
	<?php 
		}}
	?>	
	</table>
</div>